home *** CD-ROM | disk | FTP | other *** search
-
- ( --------------------------------------------
- *** HeliOS Intuition Gadget Example ***
- --------------------------------------------
-
- This demonstration code shows how to set up an absolutely standard
- Amiga intuition based gadget program, including the initialisation of
- Intuition structures etc.
-
- In fact, this code is included only as an exercise in how to initialise
- structures at run-time, which needs to be done in HeliOS if you allocate
- 32-bit addressed data structures within the 16-bit dictionary space.
-
- Usually it is better to allocate all Amiga data structures dynamically
- at run time rather than initialise them in the 16-bit dictionary space.
-
- Nevertheless, this code does at least give you an alternative approach
- which is OK for very simple applications.
-
- Actually, HeliOS contains a set of special routines which handle all
- Gadget allocation and useage in a comprehensive way, and these special
- HeliOS gadget routines insulate you from all "housekeeping" tasks such
- as the initialisation of structures.
-
- The special HeliOS gadget routines are very powerful and you will find
- that using them is very easy - far preferable, in fact, to the methods
- used here. The fact is, though, that they insulate you to such an extent
- from the "hard work" of dealing directly with Intuition that you would
- not be aware of the way Intuition gadget structures really work.
-
- For the above mentioned reason we think you should at least be familiar
- with the "long winded" method used here, before using the "easy way".
-
- Interestingly, to give you a "taste of what is to come", using the
- special HeliOS gadget system all you have to do to set up, say, 25
- gadgets is to allocate the gadgets like this:
-
- 25 GADGETS
-
- Then to initialise a particular gadget, you merely say something like
-
- 20 20 100 40 (GAD1ACTION) 1 MOVEGADGET
-
- to place gadget "1", sized 100x40, to do (GAD1ACTION), at position 20 20.
-
- Then you say 1 ONGADGET or 1 OFFGADGET.......and one word GADCHECK
- will automatically carry out the gadget action.
-
- The code below is rather more involved, but is nevertheless an example
- of how to use standard Amiga programing techniques.
-
- ---------------------------------------------------------------------
-
- So, to deal with the present code......this HeliOS source code module
- contains:
-
- 1. A fully commented predefined Intuition Gadget data structure.
-
- 2. Run-time gadget initialisation code for setting up the internal
- 32-bit pointers of structures allocated in the 16-bit dictionary.
-
- 3. A fully functional gadget command interpreter which can, if required,
- easily be integrated with a Helios menu command interpreter.
-
- 4. A simple Demo program which opens a Workbench window and
- carries out gadget commands.
-
- All the material can be readily modified to your own specific
- requirements and provides a simple basis for dealing with other
- similar structure-oriented Amiga OS programming tasks.
-
- To produce your own application all you need to do is alter the
- data structures to suit your particular requirements, then enter
- your own routines into the command vector table in place of the
- Demo commands.
-
- The run-time initialisation routines have been written in such
- a way as to be very easy to understand and modify, but this
- is not ideal in terms of speed and efficiency. Once you are
- confident about what is happening you can easily speed up this
- initialisation code if you wish, and it may be a worthwhile exercise
- to do so.
-
-
-
- <<< *** IMPORTANT *** >>>
-
- WHY RUN-TIME INITIALISATION ?
-
- WHY NOT INITIALISE THE STRUCTURE AS IT IS DECLARED?
-
-
- You MUST dynamically set up all data structure links and pointers
- at run-time if you wish to be able to save the data structure as
- part of a precompiled HeliOS code module.
-
- This has to be done because your data structures will obviously (?!) not
- be reloaded into the same absolute position in memory as they occupied
- when you first created them. This means that all the absolute pointers
- in the structure must be re-initialised each time the module is loaded. )
-
- \ ----------------------------------------------------------
- \ "FORGET" all but core dictionary.
- \ ----------------------------------------------------------
-
- FORGET **CORE**
-
- \ ----------------------------------------------------------
- \ First we define all the Text Strings we require.
- \ (In this case we are using 6 gadgets, all with text.)
- \ Edit the text strings below to your own requirements.
- \ ----------------------------------------------------------
- CREATEL GADGET1$ <$ Gadget1$
- CREATEL GADGET2$ <$ Gadget2$
- CREATEL GADGET3$ <$ Gadget3$
- CREATEL GADGET4$ <$ Gadget4$
- CREATEL GADGET5$ <$ Gadget5$
- CREATEL GADGET6$ <$ Gadget6$
- \ ----------------------------------------------------------
- \ Now set up Gadget data structure, unlinked at this stage.
- \ Note that we only need remember the address of the first,
- \ and also that we store each gadget's Intuitext structure
- \ immediately after the gadget for ease of initialisation.
- \ -----------------------------------------------------------
- \ Gadget Structure
- \ -----------------------------------------------------------
- \ GADGET1 (Boolean)
- \ -----------------------------------------------------------
- 0. DVARIABLEL GADGLIST \ Next Gadget
- 40 , \ LEdge
- 60 , \ TEdge
- 80 , \ Width
- 16 , \ Height
- 0 , \ Flags
- 1 , \ Activation
- 1 , \ Type
- 0. D, \ Render 18-offset
- 0. D, \ Select Render
- 0. D, \ Text 26-offset
- 0. D, \ MExclude
- 0. D, \ Special Info
- 1 , \ ID
- 0. D, \ User Data 44-Bytes
- \ ----------------------------------------------------------
- 1 C, \ FPEN Gadget1 Text
- 0 C, \ BPEN
- 1 C, \ MODE
- 0 C, \ KLUDGE
- 11 , \ LEDGE
- 4 , \ TEDGE
- 0. D, \ FONT
- 0. D, \ TEXT 12-offset
- 0. D, \ NEXTTEXT 20-Bytes
- \ -----------------------------------------------------------
- \ GADGET2 (Boolean)
- \ -----------------------------------------------------------
- 0. D, \ Next Gadget
- 220 , \ LEdge
- 60 , \ TEdge
- 80 , \ Width
- 16 , \ Height
- 0 , \ Flags
- 1 , \ Activation
- 1 , \ Type
- 0. D, \ Render
- 0. D, \ Select Render
- 0. D, \ Text
- 0. D, \ MExclude
- 0. D, \ Special Info
- 2 , \ ID
- 0. D, \ User Data
- \ ----------------------------------------------------------
- 1 C, \ FPEN Gadget2 Text
- 0 C, \ BPEN
- 1 C, \ MODE
- 0 C, \ KLUDGE
- 11 , \ LEDGE
- 4 , \ TEDGE
- 0. D, \ FONT
- 0. D, \ TEXT
- 0. D, \ NEXTTEXT
- \ -----------------------------------------------------------
- \ GADGET3 (Boolean)
- \ -----------------------------------------------------------
- 0. D, \ Next Gadget
- 400 , \ LEdge
- 60 , \ TEdge
- 80 , \ Width
- 16 , \ Height
- 0 , \ Flags
- 1 , \ Activation
- 1 , \ Type
- 0. D, \ Render
- 0. D, \ Select Render
- 0. D, \ Text
- 0. D, \ MExclude
- 0. D, \ Special Info
- 3 , \ ID
- 0. D, \ User Data
- \ ----------------------------------------------------------
- 1 C, \ FPEN Gadget3 Text
- 0 C, \ BPEN
- 1 C, \ MODE
- 0 C, \ KLUDGE
- 11 , \ LEDGE
- 4 , \ TEDGE
- 0. D, \ FONT
- 0. D, \ TEXT
- 0. D, \ NEXTTEXT
- \ -----------------------------------------------------------
- \ GADGET4 (Boolean)
- \ -----------------------------------------------------------
- 0. D, \ Next Gadget
- 40 , \ LEdge
- 116 , \ TEdge
- 80 , \ Width
- 16 , \ Height
- 0 , \ Flags
- 1 , \ Activation
- 1 , \ Type
- 0. D, \ Render
- 0. D, \ Select Render
- 0. D, \ Text
- 0. D, \ MExclude
- 0. D, \ Special Info
- 4 , \ ID
- 0. D, \ User Data
- \ ----------------------------------------------------------
- 1 C, \ FPEN Gadget4 Text
- 0 C, \ BPEN
- 1 C, \ MODE
- 0 C, \ KLUDGE
- 11 , \ LEDGE
- 4 , \ TEDGE
- 0. D, \ FONT
- 0. D, \ TEXT
- 0. D, \ NEXTTEXT
- \ -----------------------------------------------------------
- \ GADGET5 (Boolean)
- \ -----------------------------------------------------------
- 0. D, \ Next Gadget
- 220 , \ LEdge
- 116 , \ TEdge
- 80 , \ Width
- 16 , \ Height
- 0 , \ Flags
- 1 , \ Activation
- 1 , \ Type
- 0. D, \ Render
- 0. D, \ Select Render
- 0. D, \ Text
- 0. D, \ MExclude
- 0. D, \ Special Info
- 5 , \ ID
- 0. D, \ User Data
- \ ----------------------------------------------------------
- 1 C, \ FPEN Gadget5 Text
- 0 C, \ BPEN
- 1 C, \ MODE
- 0 C, \ KLUDGE
- 11 , \ LEDGE
- 4 , \ TEDGE
- 0. D, \ FONT
- 0. D, \ TEXT
- 0. D, \ NEXTTEXT
- \ -----------------------------------------------------------
- \ GADGET6 (Boolean)
- \ -----------------------------------------------------------
- 0. D, \ Next Gadget
- 400 , \ LEdge
- 116 , \ TEdge
- 80 , \ Width
- 16 , \ Height
- 0 , \ Flags
- 1 , \ Activation
- 1 , \ Type
- 0. D, \ Render
- 0. D, \ Select Render
- 0. D, \ Text
- 0. D, \ MExclude
- 0. D, \ Special Info
- 6 , \ ID
- 0. D, \ User Data
- \ ----------------------------------------------------------
- 1 C, \ FPEN Gadget6 Text
- 0 C, \ BPEN
- 1 C, \ MODE
- 0 C, \ KLUDGE
- 11 , \ LEDGE
- 4 , \ TEDGE
- 0. D, \ FONT
- 0. D, \ TEXT
- 0. D, \ NEXTTEXT
- \ ----------------------------------------------------------
- \ Etc etc ...... Add as many gadgets as you require.........
- \ ----------------------------------------------------------
- \ Then declare the total number of gadgets as GADGET#
-
- \ In this case there are 6 Gadgets, so ........
-
- 6 CONSTANT GADGET#
-
- \ -----------------------------------------------------------
- \ Border Structure
- \ -----------------------------------------------------------
- 0 VARIABLEL BORDER1 \ LEdge
- 0 , \ TEdge
- 3 C, \ FPen
- 0 C, \ BPen
- 1 C, \ DrawMode
- 5 C, \ Count
- 0. D, \ Coords
- 0. D, \ NextBorder
-
- 0 VARIABLEL COORD1 0 , \ Coord1
- 79 , 0 , \ Coord2
- 79 , 15 , \ Coord3
- 0 , 15 , \ Coord4
- 0 , 0 , \ Coord5
-
- \ -----------------------------------------------------------
- \ Now create words to reference the various structures
- \ ----------------------------------------------------------
-
- : GADGET \ Gadget number(w) - - - Structure Address(l)
-
- 1- 64 * \ Offset into list of gadgets
- 0 \ Make into 32-bit number
- GADGLIST D+ ; \ Add to start address
-
-
- : GADTEXT \ Gadget number(w) - - - Structure Address(l)
-
- GADGET 44. D+ ;
-
- \ ----------------------------------------------------------
- \ And now a word to initialise the gadgets.........
- \ ----------------------------------------------------------
-
- : INITGADGETS
-
- GADGET6$ GADGET5$ GADGET4$ GADGET3$ GADGET2$ GADGET1$
- GADGET# 0
- DO
- I 1+ GADTEXT 12. D+ D!L \ Set Text Strings
- LOOP
-
-
- GADGET# 0 \ Set Gadget Links
- DO
- I 1+ GADGET# <
- IF
- I 2+ GADGET
- I 1+ GADGET D!L
- THEN
- LOOP
-
- GADGET# 0 \ Set IntuiText Pointers
- DO
- I 1+ GADTEXT
- I 1+ GADGET 26. D+ D!L
- LOOP
-
- GADGET# 0 \ Set Border Pointers
- DO
- BORDER1 I 1+ GADGET 18. D+ D!L
- LOOP
-
- COORD1 BORDER1 8. D+ D!L
- ;
-
- \ ----------------------------------------------------------
- \ Demo Window Auxiliaries
- \ ----------------------------------------------------------
-
- $CONSTANT WINTITLE $GADGETDEMO$ \ Window Title for Demo window
-
- 0. DVARIABLE WINDOW1 \ DVARIABLE to contain your Window handle
-
- \ ----------------------------------------------------------
- \ Disable and enable single gadgets n1
- \ ----------------------------------------------------------
-
- : ONGADGET \ n1 - - -
-
- GADGET 0 AREG D!
- WINDOW1 D@ 1 AREG D!
- 0. 2 AREG D!
- INTUBASE -186 LIBRARY
- ;
-
- : OFFGADGET \ n1 - - -
-
- GADGET 0 AREG D!
- WINDOW1 D@ 1 AREG D!
- 0. 2 AREG D!
- INTUBASE -174 LIBRARY
- ;
-
- \ ----------------------------------------------------------
- \ Add and Remove single gadgets n1
- \ ----------------------------------------------------------
-
- : ADDGADGET \ n1 - - -
-
- GADGET 1 AREG D!
- WINDOW1 D@ 0 AREG D!
- -1. 0 DREG D!
- INTUBASE -42 LIBRARY
- ;
-
- : REMGADGET \ n1 - - -
-
- GADGET 1 AREG D!
- WINDOW1 D@ 0 AREG D!
- INTUBASE -228 LIBRARY
- ;
-
- \ ----------------------------------------------------------
- \ Refresh n2 Gadgets after n1
- \ ----------------------------------------------------------
-
- : REFRESHGADGETS \ n1 n2 - - -
-
- 0 0 DREG D!
- GADGET 0 AREG D!
- WINDOW1 D@ 1 AREG D!
- 0. 2 AREG D!
- INTUBASE -432 LIBRARY
- ;
-
- \ ----------------------------------------------------------
- \ A set of dummy Gadget commands
- \ ----------------------------------------------------------
-
- : G1 18 3 CURPUT ." GADGET1ACTION" ;
- : G2 18 3 CURPUT ." GADGET2ACTION" ;
- : G3 18 3 CURPUT ." GADGET3ACTION" ;
- : G4 18 3 CURPUT ." GADGET4ACTION" ;
- : G5 18 3 CURPUT ." GADGET5ACTION" ;
- : G6 18 3 CURPUT ." GADGET6ACTION" ;
-
- \ ----------------------------------------------------------
- \ The Gadgetnumber
- \ ----------------------------------------------------------
-
- \ See the Helios Dictionary for full definition and description
- \ of the Gadgetnumber.
- \ Very briefly, the HeliOS Gadgetnumber is similar to a
- \ menunumber and has the following format:
-
- \ Gadgetnumber in Binary Format: 0000000001011111
- \ These bits are always set ^^^^^
- \ and indicate that this is a Gadget, not a Menu Number.
-
- \ Gadgetnumber in Binary Format: 0000000001011111
- \ Gadget number bits ^^^^^^^^^^^ = Gadget 2
-
- \ You can replace the commands G1.......G6 defined above and used
- \ in the Gadgetvector table below with any routines of your own.
-
- \ ----------------------------------------------------------
- \ The Gadget Command Interpreter Vector Table
- \ ----------------------------------------------------------
-
- BIN 0000000000111111 VARIABLE GADGETVECTORS \ Gadget 1
- ' G1 CFA ,
- 0000000001011111 , \ 2
- ' G2 CFA ,
- 0000000001111111 , \ 3
- ' G3 CFA ,
- 0000000010011111 , \ 4
- ' G4 CFA ,
- 0000000010111111 , \ 5
- ' G5 CFA ,
- 0000000011011111 , \ 6
- ' G6 CFA , DECIMAL
- HERE
- 255 ,
- ' NOOP CFA ,
- CONSTANT GADGEND
-
- \ --------------------------
- \ Gadget Command Interpreter
- \ --------------------------
-
- : GADGCHECK
-
- GADGEND
- GADGETVECTORS
- DO
- I DDUP @
- =
- IF
- 2+ LEAP
- THEN
- DROP
- 4
- +LOOP
- GADGEND 2+
- ;
-
- : GADGETACTION DROP GADGETNUMBER GADGCHECK @EXECUTE ;
-
- \ ---------------------
- \ Demonstration Program
- \ ---------------------
-
- : TESTGADGETS
-
- TIMEOFF \ Switch off auto-time display
-
- INITGADGETS \ Initialise Gadget structures
-
- STDWINDOW \ Set up for standard Workbench window
-
- DRAGGAD \ Include Drag Gadget
-
- DEPTHGAD \ Include Depth Gadget
-
- CLOSEGAD \ Include Close gadget ..........
-
- WINDOWCLOSE 0! \ ..and set up Window Close Gadget Flag
-
- GADGLIST WINDOWSTRUCT 18 + D! \ Install Gadget List in Window Struct
-
- WINTITLE \ Window Title Text String
-
- 0 0 520 200 \ Window Dimensions
-
- 2 0 \ 2-Bitplanes, no Superbitmap
-
- OPENWINDOW \ Now, at last, open the new Window
-
- DFLAG0= IF \ ??? Window failed to open ???
- DDROP \ We have no window, so finish
- ELSE
- DTRIP \ Our window opened OK, so......
- WINDOW1 D! \ Store window handle
- MAKEINWINDOW \ Make Inputwindow
- MAKEOUTWINDOW \ Make Outputwindow
- CUROFF \ Switch off cursor
- 1 GADGET# \ From 1st gadget, all gadgets
- REFRESHGADGETS \ Display Gadgets
- EVENTON \ Switch on Event Reporting
- WBENCHTOFRONT \ Display Workbench
-
- CR CR ." Hello!" \ Hailing Text
-
- 0 17 CURPUT \ Set Text Start Position
-
- ." Try all the Gadgets." CR
-
- ." Press <Esc> to exit this Demo," CR
-
- ." or Click on the window CLOSE Gadget."
-
- BEGIN \ Input processing loop
- KEY
- DUP 1253 = IF GADGETACTION THEN
- 27 = \ Check for <Esc>
- WINDOWCLOSE @ OR \ or Window Close Gadget
- UNTIL \ Now Clean-up and Exit
-
- FORTHOUTWINDOW \ Reset HeliOS Output
- FORTHINWINDOW \ Reset HeliOS Input
- WINDOW1 D@ CLOSEWINDOW \ Close Window
- THEN
- TIMEON \ Switch on auto-time display
- WBENCHTOBACK \ Move Workbench to back
- ;
-
- TESTGADGETS
-
- \ ---------------------------------------------------------------------------
- \ The End
- \ ---------------------------------------------------------------------------
-